#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import threading

### ###########################################################
# Decorator to threading lock a function
#


class locktan(object):
    lock = threading.RLock()

    def __call__(self, fn):
        def lockfn(*args, **kwargs):
            locktan.lock.acquire()
            try:
                result = fn(*args, **kwargs)
            except:
                raise
            finally:
                locktan.lock.release()
            return result

        return lockfn
